/**
 * 
 */
package com.angel.test;

import javax.servlet.http.HttpServletRequest;

import org.junit.After;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;

import com.angel.architecture.context.ExecutionContext;
import com.angel.architecture.dtos.LoginInfoDTO;
import com.angel.architecture.services.LoginService;


/**
 * @author William
 *
 */
public abstract class GenericLoginTransactionalTestCase extends GenericTransactionalSpringTestCase{

	@Autowired
	private LoginService loginService;
	
	protected abstract LoginInfoDTO getLoginInfoDTO();
	
    @Before
    public void login() {
        HttpServletRequest request = new MockHttpServletRequest();
        ExecutionContext.getContext().setRequest(request);

        this.getLoginService().login(this.getLoginInfoDTO());
        //ExecutionContext.getContext().getRequest().getSession(true).setAttribute(SecurityService.SESION_USUARIO, sessionUserDTO);
    }
    
    @After
    public void logout() {
    	this.getLoginService().logout(this.getLoginInfoDTO());
        //TODO Do it in logout message in LoginService. ExecutionContext.getContext().setRequest(null);
    }

	/**
	 * @return the loginService
	 */
	protected LoginService getLoginService() {
		return loginService;
	}

	/**
	 * @param loginService the loginService to set
	 */
	protected void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
}
